/*copyright 2009 Kevin Daley
#This file is a part of Cerebra.
#Cerebra is free software: you can redistribute it and/or modify
 #   it under the terms of the GNU  General Public License as published by
  #  the Free Software Foundation, either version 3 of the License, or
   # (at your option) any later version.

   # This program is distributed in the hope that it will be useful,
   # but WITHOUT ANY WARRANTY; without even the implied warranty of
   # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   # GNU  General Public License for more details.

   # You should have received a copy of the GNU  General Public License
   # along with this program.  If not, see <http://www.gnu.org/licenses/>.

#Kevin Daley, Lead Developer.  still.horse@gmail.com.*/
#include <Python.h>
#include <arrayobject.h>
#include "host.cu"
#include <cmath>
extern "C" void initialize( long N, PyObject* input, PyObject* bnd, PyObject* spectrum){
long sz=1024;
long num_palette= 64;
float* Data= (float*) ((PyArrayObject*) input)->data;
float* Data2=(float*) ((PyArrayObject*) spectrum)->data;
float* Data3=(float*) ((PyArrayObject*) bnd)->data;
         
        network* k=(network*) N;
        k->uspect=(float*) malloc(num_palette*sizeof(float));
        k->nu=(float*) malloc(sz*sz*num_palette*sizeof(float)+sz*sz*sizeof(float)+sz*sizeof(float));
	k->ju=(float*) malloc(sz*sz*sizeof(float)+sz*sizeof(float));
        cudaMemcpy2D((void*)k->uspect, 1,(void*)Data2,(((PyArrayObject*) spectrum)->strides[0]), 64*sizeof(float),1, cudaMemcpyHostToHost);
	cudaMemcpy2D((void*)k->nu, 1,(void*)Data,(((PyArrayObject*) spectrum)->strides[0]), (65*1024*1024+1024)*sizeof(float),1, cudaMemcpyHostToHost);
	cudaMemcpy2D((void*)k->ju, 1,(void*)Data3,(((PyArrayObject*) bnd)->strides[0]), (65*1024*1024+1024)*sizeof(float),1, cudaMemcpyHostToHost);
	k->wakeup=1;
       

        k->setup(2, sz, num_palette);
	
}
 void save(long N, PyObject* input){
	network* k=(network*) N;
	long sz=1024;
	long num_palette= 64;
	cudaFree(k->j);
	cudaFree(k->J);
	float* Data= (float*)((PyArrayObject*) input)->data;
	cudaFree(k->spectrum);
	cudaMemcpy2D((void*)Data, ((PyArrayObject*) input)->strides[0],(void*)k->n,1, k->siz,1, cudaMemcpyDeviceToHost);
}



